#ifndef HTTP_API_H
#define HTTP_API_H

#include <iostream>
#include <string>
#include <fstream>
#include <sys/stat.h>
#include <ctime>
#include <iomanip>
#include "Tools.h"
#include "DatabaseUtil.h"

struct UserInfo
{
    std::string userID;
    std::string userName;
    long lastLoginTime;
};

class HttpApi
{
public:
    HttpApi(){};
    ~HttpApi(){};

    static bool DataBaseOperation(Json::Value& responseContent,
        const Json::Value& condition, const std::string& tableName, const std::string& operation);

    static bool GetCameraFlv(Json::Value& responseContent, const Json::Value& cameraInfo);
    static bool StopCameraFlv(Json::Value& responseContent, const Json::Value& cameraInfo);

    static bool LogIn(Json::Value& responseContent, const Json::Value& userData);
    static bool GetUser(Json::Value& responseContent, const Json::Value& condition);

    static bool HasAlgorithm(Json::Value& responseContent, const Json::Value& condition);
    static bool UpdateAlgorithmBinding(Json::Value& responseContent, const Json::Value& condition);
    static bool AlgorithmDelete(Json::Value& responseContent, const Json::Value& condition);

    static bool AddAlarm(Json::Value& responseContent, Json::Value& data);
    static bool AlarmHandle(Json::Value& responseContent, Json::Value& data, const UserInfo& userName);
    static bool GetAlarmStatistics(Json::Value& responseContent, Json::Value& data, bool isTime);
    static bool GetAlarmImage(std::string& image, const std::string& imagePath, std::string& contentType);

    static bool GetAreaTree(Json::Value& responseContent, const Json::Value& condition);
    static bool GetMenuTree(Json::Value& responseContent, const Json::Value& condition);

    static bool AlarmExport(std::string& fileContent, const Json::Value& alarmGuids);
    static bool GetFile(std::string& response, const std::string& filePath);
    static std::string getContentType(const std::string &path);//转换内容类型的格式
    static bool fileExists(const std::string &path);//检查文件是否存在
    static std::string readFile(const std::string &path);//读取文件

    static std::unordered_map<std::string, UserInfo> accessIds;//当前存储的访问标识
    static std::unordered_map<std::string, pid_t> ffmpegPid;//当前存储的访问标识
};


#endif